package com.roy.spring.utils;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;

import java.io.Serializable;
import java.util.Properties;

/**
 * 自定主键生成器
 * 参考 SelfModel 的使用.
 * Created by admin on 17-12-23.
 */
public class SequenceGenerator implements IdentifierGenerator, Configurable {

    public SequenceGenerator(){
    }

    @Override
    public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {

    }

    /*@Override
    public Serializable generate(SessionImplementor session, Object object) throws HibernateException {
        return Sequence.getSequence();
    }*/

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return Sequence.getSequence();
    }
}
